<?php

include('includes/connect.php');

$user=$_POST['user'];
$count=$_POST['count'];

	$usr=mysql_query("select * from user_attempt where user='".$user."'");
	$fetch=mysql_fetch_array($usr);
	
	$ud=$fetch['user_attempt'];	
	 
	  	  
			  if(mysql_num_rows($usr)>0)
			  {
			   
				$user_attempt=	$ud+1;
				
				$s=mysql_query("update user_attempt set user_attempt='".$user_attempt."' where user='".$user."'");
				}
		  	  else
			  {
			  	$user_attempt1=1;
				$s=mysql_query("insert into user_attempt(`user`,`user_attempt`)values('$user','$user_attempt1')");
			  }	
				

				
				if($s)
				{
					for($i=1;$i<=$count;$i++)
							{
					
							  $Questions_ID=$_POST["questions".$i];
							  $Options_ID=$_POST["options".$i];
						      $usr1=mysql_query("select * from user_attempt where user='".$user."'");
							  $ui_fetch1=mysql_fetch_array($usr1);
							  $attemt_id=$ui_fetch1['user_attempt'];
							  $user_id=$ui_fetch1['uid'];
							   									
							$s1=mysql_query("INSERT INTO test_attempted(`uid`,`qid`,`opt_id`,`attemt_id`)VALUES('$user_id','$Questions_ID','$Options_ID','$attemt_id')");
							
							}
				}
		  
	 if($s1)
	 {
	 header("location:score.php");
	 
	 }


/*

foreach($_POST['q'] as $a => $h) 
		 {
		 	$sql="select * from questions where qid='".$h."'";
			$r1=mysql_query($sql);
			$row15=mysql_fetch_array($r1);
			extract($row15);
			$iidd=$row15['qid'].'<br>';
			echo 'ques'.$iidd; 
	
			 
		}
		


//$sql = mysql_query("select * from options where opt_id=".$iidd);


*/

?>